package fem2.strategies;

import inf.jlinalg.ArrayVector;
import inf.jlinalg.SolveFailedException;
import fem2.Model;
import fem2.analysis.Analysis;
import fem2.analysis.LinearStaticAnalysis;
import fem2.jlinalg.Solver;

public class LinearBucklingStrategy extends BucklingStrategy {

	public LinearBucklingStrategy(Model m, int nBucklingMode) {
		super(m);
		this.nBucklingMode = nBucklingMode;
	}

	@Override
	public void iterationStarted(Solver leftHandSideSolver, ArrayVector rightHandSide, ArrayVector u) {
		/********************************
		 * solve for first displacement
		 ********************************/
		Analysis an = new LinearStaticAnalysis(model);
		an.run();
	}

	@Override
	public boolean iterationFinished(Solver leftHandSideSolver, ArrayVector rightHandSide,
			ArrayVector u) {
		/*
		 * assemble Kt
		 */
		model.assembleKt(this.geSolver.getA());
		/*
		 * assemble Kg
		 */
		this.assembleKg(model, this.geSolver.getB());
		/*
		 * solve
		 */
		try {
			geSolver.solve();
		} catch (SolveFailedException e) {
			throw new Error("Solve failed");
		}
		return true;
	}
}
